namespace RSCore.Files;
public sealed record class ItemFile(string Name) : RSFile(Name), IKeyConvertable
{
	public string DisplayName { get; set; } = Name.GetDefaultDisplayName();
	public string Tooltip { get; set; } = string.Empty;
	public override void Deserialize(JsonValue json)
	{
		DisplayName = json.GetText(nameof(DisplayName));
		Tooltip = json.GetText(nameof(Tooltip));
	}

	public IEnumerable<KeyValuePair<KeyData, string>> Convert()
	{
		yield return new(new(Name, EntryType.Item, nameof(DisplayName)), DisplayName);
		yield return new(new(Name, EntryType.Item, nameof(Tooltip)), Tooltip);
	}

	public override void Load(BinaryReader reader)
	{
		DisplayName = reader.ReadString();
		Tooltip = reader.ReadString();
	}

	public override void Save(BinaryWriter writer)
	{
		writer.Write(DisplayName);
		writer.Write(Tooltip);
	}

	public override JsonValue Serialize()
	{
		return new JsonObject
		{
			{ nameof(DisplayName), DisplayName },
			{ nameof(Tooltip), Tooltip },
		};
	}

	public override void Write(StreamWriter writer, RSFile? annotation)
	{
		var orig = annotation as ItemFile;
		writer.WriteProperty(DisplayName, orig?.DisplayName);
		writer.WriteProperty(Tooltip, orig?.Tooltip);
	}

	public override void Read(StreamReader reader)
	{
		var properties = reader.ReadProperties();
		DisplayName = properties.GetText(nameof(DisplayName));
		Tooltip = properties.GetText(nameof(Tooltip));
	}
}